# Generates online and print versions of SGML source file.
BASENAME=concorrencia

# SGML source file.
DOCBOOK_FILE=$(BASENAME).xml
STYLESHEET=db2latex.xsl

PROC=xsltproc
MAKEINDEX=makeindex
PDFLATEX=pdflatex

# Generated files.
TEX_FILE=$(BASENAME).tex
PDF_FILE=$(BASENAME).pdf
IDX_FILE=$(BASENAME).idx
IND_FILE=$(BASENAME).ind

xsl_params =

# xsl_params = paper.type draft.mode fop.extensions passivetex.extensions \
#              section.autolabel section.label.includes.component.label \
#              table.cell.border.thickness hyphenate \
#              xref.with.number.and.title

# paper.type = A4  # default: USletter
# draft.mode = no  # default: maybe
# hyphenate = false  # default: true
# fop.extensions = 0
# passivetex.extensions = 0
# section.autolabel = 1
# section.label.includes.component.label = 1
# table.cell.border.thickness = 0.25pt  # default: 0.5pt
# xref.with.number.and.title = 0

XSL_PARAMS := $(foreach param, $(xsl_params), --stringparam $(param) $($(param))) --xinclude

# Build rules.
tex: $(TEX_FILE)

pdf: $(PDF_FILE)

all: tex pdf

clean:
	 rm -f $(BASENAME).{htm,log,aux,ps,pdf,tex,dvi,rtf,fot,brf,out}
	 rm -f *~
	 rm -f *.html

distclean: clean
	 rm -f $(BASENAME).tgz

package:
	 rm -f $(BASENAME).tgz
	 tar -C .. -czf /tmp/$(BASENAME).tgz $(BASENAME)
	 mv /tmp/$(BASENAME).tgz .

dist: clean package

distall: all package

$(IND_FILE): $(IDX_FILE)
	$(MAKEINDEX) -o $(IND_FILE) $(IDX_FILE)

# Compile rules.
$(TEX_FILE):
	$(PROC) $(XSL_PARAMS) -o $(TEX_FILE) $(STYLESHEET) $(DOCBOOK_FILE)

$(PDF_FILE): $(TEX_FILE) $(IND_FILE)
	sed -i 's/portugese/portuges/g' $(TEX_FILE); \
	$(PDFLATEX) $(TEX_FILE); \
	$(PDFLATEX) $(TEX_FILE); \
	$(PDFLATEX) $(TEX_FILE)


